﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Chinaer.UI.MVC.Helper
{
    public class JsonHelper
    {
        public static string GetJson(object obj, int totals)
        {
            string json = CreateJson(obj);
            return GetJson(json, totals);
        }
        public static string GetJson(string obj, int totals)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("{");
            sb.Append("\"totals\":");
            sb.Append(totals.ToString());
            sb.Append(",\"rows\":");
            sb.Append(obj);
            sb.Append("}");
            //sb.AppendFormat(string.Format("{2}\"totals\":{0},\"rows\":[{1}]{3}", totals.ToString(), obj, "{", "}"));
            return sb.ToString();

        }
        public static string CreateJson(object obj)
        {
            return Newtonsoft.Json.JsonConvert.SerializeObject(obj);
        }
    }
}